﻿

namespace EFS.RC.CC.CH.Tables
{
	public static class HuntGroups
	{
		/// <summary>
		/// Load internals from data row
		/// </summary>
		/// <param name="row"></param>
		internal static EFS.RC.CC.CH.Entities.HuntGroup Load(System.Data.DataRow row)
		{
			// check
			EFS.Common.Verify.Reference(row, "row");

			// loaded
			EFS.RC.CC.CH.Entities.HuntGroup loaded = new EFS.RC.CC.CH.Entities.HuntGroup();

			// ID
			loaded.ID = EFS.DB.DataRow.Int32(row, "ID");

			// Name
			loaded.Name = EFS.DB.DataRow.String(row, "NAME");

            // Sip

			loaded.Sip = EFS.DB.DataRow.String(row, "SIP");
			// done
			return loaded;
		}

		/// GetAll
		public static EFS.RC.CC.CH.Entities.HuntGroup[] GetByAll()
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.CH.QRDConnection.New)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.CH.Entities.HuntGroup>(
					"[dbo].[HuntGroups_GetAll]",
					null,
					Load);
			}
		}

		/// GetByID
		public static EFS.RC.CC.CH.Entities.HuntGroup GetByID(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.CH.QRDConnection.New)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.CH.Entities.HuntGroup>(
					"[dbo].[HuntGroups_GetByID]",
					new EFS.DB.Parameters.Array("id", id),
					Load);
			}
		}

		/// Create
		public static System.Int32? Create(
			System.String name,System.String sip)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.CH.QRDConnection.New)
			{
				// make params
				EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
					new System.String[] { "name","sip", "id" },
					new System.Object[] { name,sip, default(System.Int32) },
					new System.Boolean[] { false,false, true });

				// ok
				connection.DoExecuteNonQuery("[dbo].[HuntGroups_Create]", parametersArray);

				// get id value
				return parametersArray.GetOutPrameterValue<System.Int32?>("id");
			}
		}

		/// Update
		public static void Update(
			System.Int32 id,
			System.String name,
			System.String sip)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.CH.QRDConnection.New)
			{
				connection.DoExecuteNonQuery(
					"[dbo].[HuntGroups_Update]",
					new EFS.DB.Parameters.Array(
						new System.String[] { "id", "name","sip" },
						new System.Object[] { id, name,sip }));
			}
		}

		/// Delete
		public static void Delete(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.CH.QRDConnection.New)
			{
				connection.DoExecuteNonQuery("[dbo].[HuntGroups_Delete]", new EFS.DB.Parameters.Array("id", id));
			}
		}
	}
}
